﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using PoolGame2.Controls;

namespace PoolGame2.Game
{
    class CueCamera : MoveableCamera
    {
        Vector3 offset = new Vector3(0,10,0);
        private Cue cue;

        public CueCamera(PoolGame game, Cue cue) : base(game)
        {
            this.cue = cue;
            DefaultProjection();
            cameraPosition = cue.getPosition();
            cameraPosition.Y += 8.0f;

        }

        public override void UpdateCamera(GameTime gametime)
        {
            cameraPosition = cue.getPosition();
            cameraPosition += offset;

            cameraPosition += cue.GetUnitVectorDirection()*45;

            Vector3 viewDirection = Vector3.Negate(cue.GetUnitVectorDirection());
            cameraTarget = cue.getPosition() + viewDirection;
            cameraTarget.Y += 4.0f;
            viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up); 
            //UpdateViewMatrix();
        }

        public override void GameControlPerformed(List<GameControlAction> actions)
        {
            if (this.activeCamera)
            {
                foreach (GameControlAction action in actions)
                {
                    ControlActions a = action.GetAction();

                    if (a == ControlActions.ANALOG2_MOVE)
                    {
                        offset.Y += (float)action.GetProperty(GameConstants.Y_CHANGE);// *GameConstants.CAMERA_MOVEMENT_SCALE;
                        if (offset.Y < 10)
                        {
                            offset.Y = 10;
                        }
                        if (offset.Y > 100)
                        {
                            offset.Y = 100;
                        }
                            Vector3 cueDirection = cue.GetUnitVectorDirection();
                            //offset.X = cueDirection.X * (offset.Y * 0.5f);
                            //offset.Z = cueDirection.Z * (offset.Y * 0.5f);
                    }
                }
            }
        }

    }
}
